package com.example.hotelmanagement.service.impl;

import com.example.hotelmanagement.common.pojo.PageResult;
import com.example.hotelmanagement.domain.entity.Room;
import com.example.hotelmanagement.domain.vo.RoomPageReqVo;
import com.example.hotelmanagement.mapper.RoomMapper;
import com.example.hotelmanagement.service.RoomService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;

import javax.annotation.Resource;

/**
 * 房间信息(Room)表服务实现类
 *
 * @author makejava
 * @since 2023-06-10 17:32:51
 */
@Service("roomService")
public class RoomServiceImpl implements RoomService {
    @Resource
    private RoomMapper roomDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Room queryById(Long id) {
        return roomDao.selectById(id);
    }

    /**
     * 分页查询
     *
     * @param room 筛选条件
     * @return 查询结果
     */
    @Override
    public PageResult<Room> queryByPage(RoomPageReqVo room) {
        return roomDao.selectPageByCondition(room);
    }

    /**
     * 新增数据
     *
     * @param room 实例对象
     * @return 实例对象
     */
    @Override
    public Room insert(Room room) {
        room.setId(null);
        roomDao.insert(room);
        return room;
    }

    /**
     * 修改数据
     *
     * @param room 实例对象
     * @return 实例对象
     */
    @Override
    public Room update(Room room) {
        roomDao.updateById(room);
        return queryById(room.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return roomDao.deleteById(id) > 0;
    }
}
